#include "SDLInput.hpp"

#include <SDL/SDL.h>

SDLInput::SDLInput(IInputHandler* handler) : m_handler(handler)
{
	
}

void SDLInput::update()
{
	/* Check for SDL events */
	SDL_Event event;
	while( SDL_PollEvent(&event) )
	{
		switch (event.type)
		{
		case SDL_KEYDOWN:
			m_handler->onKeyDown(this, event.key.keysym.sym);
			break;
		case SDL_QUIT:
			m_handler->onQuit(this);
			break;
		case SDL_MOUSEBUTTONDOWN:
			// TODO: I think the conversion to world coordinates can be done in
			//       game code.
			//m_listener->onMouseDown(m_Camera.convertPxl2WorldCoord( Vector3D(m_Event.button.x, m_Event.button.y) ), 
			//						m_Event.button.button);
			m_handler->onMouseDown(this,
								   Vector(event.button.x, event.button.y),
								   event.button.button);
			break;
		case SDL_MOUSEMOTION:
			m_handler->onMouseMove(this,
								   Vector(event.button.x, event.button.y),
								   event.button.button);
			break;
		default:
			break;
		}
	}
};
